echo "Usage:openstack_install.sh <CONTROLLER IP> <GLANCE SERVER IP> <SERVICE NIC>"
echo "Are you specify controller IP($1)?"
echo "Are yor sure Glance IP($2)?"
echo "Are you sure SVC NIC($3)?"
echo "SVC NIC info"
echo "Desktop    : p1p1"
echo "Workstation: p4p1"
echo "Atom       : p2p2"
echo "ex) ./openstac_install.sh 192.168.1.224 192.168.1.223 p2p2"
echo "The number of arguments is: $#"

if [ $# -eq 3 ]
then
        echo "success"
else
        echo "fail"
        exit
fi

echo "going..."


sleep 5


msg="s/%SERVER%/$1/g"
msg2="s/%GLANCE_SERVER%/$2/g"
apt-get update
apt-get -y install qemu-system-x86
apt-get -y install xtightvncviewer
apt-get -y install nova-compute-kvm
rm -f /etc/nova/api-paste.ini
wget -O /etc/nova/api-paste.ini http://192.168.1.254/openstack/compute/api-paste.ini
rm -f /etc/nova/nova.conf
wget -O /etc/nova/nova.conf http://192.168.1.254/openstack/compute/nova.conf
sudo sed -i $msg /etc/nova/nova.conf
sudo sed -i $msg2 /etc/nova/nova.conf


apt-get -y install openvswitch-switch neutron-plugin-openvswitch-agent
rm -f /etc/init/neutron-plugin-openvswitch-agent.conf
wget -O /etc/init/neutron-plugin-openvswitch-agent.conf http://192.168.1.254/openstack/neutron/neutron-plugin-openvswitch-agent.conf
rm -f /etc/neutron/netron.conf
wget -O /etc/neutron/neutron.conf http://192.168.1.254/openstack/neutron/neutron.conf
sudo sed -i $msg /etc/neutron/neutron.conf

rm -f /etc/neutron/api-paste.ini
wget -O /etc/neutron/api-paste.ini http://192.168.1.254/openstack/neutron/api-paste.ini
sudo sed -i $msg /etc/neutron/api-paste.ini

mkdir /etc/neutron/plugins/ml2
wget -O /etc/neutron/plugins/ml2/ml2_conf.ini http://192.168.1.254/openstack/neutron/ml2_conf.ini
sudo sed -i $msg /etc/neutron/plugins/ml2/ml2_conf.ini

ovs-vsctl add-br br-int
ovs-vsctl add-br br-ex
ovs-vsctl add-port br-ex $3
ifconfig $3 up

service nova-compute restart
service neutron-plugin-openvswitch-agent restart
